﻿@{
    ViewData["Title"] = "操作日志";
}

<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                @ViewData["Title"]
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">
        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <script type="text/html" id="toolbarAE">
        <div>
            @if (await Authorizer.AuthView(PermissionKeys.Log_Clear))
            {
                     <button class='layui-btn layui-btn-sm data-clear-btn'><i class='layui-icon'>&#xe640;</i>清除所有日志</button>
            }
            </div>
    </script>

    <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="NameTpl">
        {{d.deptName}} - {{d.nickname}}
    </script>
    <script type="text/html" id="doThingTpl">
        {{# var dothing = JSON.parse(d.doThing) }}
        {{#if(dothing.status==1){ }}
        <span class="layui-badge layui-bg-green">成功</span>
        {{# }else{ }}
        <span class="layui-badge layui-bg-orange">失败</span>
        {{# } }}
        {{ dothing.msg }}
    </script>
</div>

<script>
    layui.define(function () {
        var table = layui.table, $ = layui.jquery, form = layui.form;
        table.render({
            elem: '#currentTableId',
            url: '/Admin/Log/Index?json=1',
            toolbar: '#toolbarAE',
            cols: [[
                { field: 'id', title: 'Id', width: 100 },
                { field: 'username', title: '用户', templet: '#NameTpl', width: 220 },
                { field: 'controllerAction', title: '方法', width: 220 },
                { field: 'ip', title: 'Ip', sort: true, width: 160 },
                { field: 'time', title: '时间', sort: true, width: 180 },
                { field: 'name', title: '标识', sort: true, width: 140 },
                { field: 'doThing', title: '记录', templet: '#doThingTpl' },
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 20,
            id: 'tableReload',
            page: true
        });

        $(".data-clear-btn").on("click", function () {
            layer.confirm('清除所有数据库操作日志？', function (index) {
                $.post('/Admin/Log/Clear', function (res) {
                    if (res.status == 1) {
                        layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                            table.reloadData('tableReload');
                            layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                    }
                });
            });
            return false;
        });
    });
</script>
